using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Activa.CoolStorage;
using CodeStory.Core;
using CodeStory.Core.ObjectEntity;
using CodeStory.Core.UI;

namespace CodeStory.WebApplication.Modules.Core.Admin
{
	[NavigationPortlet("CodeStory_Core_Admin_ModuleManager")]
	public partial class ModuleManager : Portlet
	{
		protected override void OnInit(EventArgs e) {
			Load += new EventHandler(ModuleManager_Load);
			GridView1.RowCommand += new GridViewCommandEventHandler(GridView_RowCommand);
			base.OnInit(e);
		}

		void ModuleManager_Load(object sender, EventArgs e) {
			//throw new Exception("The method or operation is not implemented.");
			if (!IsPostBack && !EditMode) {
				BindModules();
			}
		}

		private void BindModules() {
			CSList<ModuleObject> list = ModuleObject.List();
			GridView1.DataSource = list;
			GridView1.DataBind();
		}

		void GridView_RowCommand(object sender, GridViewCommandEventArgs e) {
			//throw new Exception("The method or operation is not implemented.");
			if (e.CommandName == "DeleteModule") {
				Guid id = new Guid(e.CommandArgument.ToString());
				ModuleObject.Read(id).Delete();
			}
			BindModules();
		}
	}
}